package com.baizhi.springboot.controller;

import com.baizhi.springboot.entity.Lesson;
import com.baizhi.springboot.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@RestController
@Controller
public class LessonController {
    @Autowired
    private LessonService lessonService;

    @RequestMapping("/selectCounterByPage")
    public Map selectCounterByPage(Integer page, Integer limit, Integer lessonId) {
        return lessonService.selectCounterByPage(page, limit, lessonId);
    }

    @RequestMapping("/selectLessonByPage")
    public Map selectLessonByPage(Integer page, Integer limit, String name) {
        return lessonService.selectLessonByPage(page, limit, name);
    }

    @RequestMapping("insertLesson")
    public Map insertLesson(Lesson lesson) {
        HashMap<Object, Object> map = new HashMap<>();
        lesson.setLessonStatus(0);
        try {
            lessonService.insertLesson(lesson);
            map.put("isAdd", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isAdd", false);
        }
        return map;
    }
    @RequestMapping("/deleteLesson")
    @ResponseBody
    public Map  deleteLesson(Integer id){
        HashMap<Object, Object> map = new HashMap<>();

        try {
            lessonService.deleteLesson(id);
            map.put("isDelete", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDelete", false);
        }
        return map;
    }
}
